package com.example.demo.controller.front;

import com.example.demo.dao.Activity;
import com.example.demo.dao.Comment;
import com.example.demo.dao.Goods;
import com.example.demo.service.CommentService;
import com.example.demo.service.GoodsService;

import com.example.demo.service.activityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
@RequestMapping("/goods")
public class mainController {
    @Autowired
    private GoodsService goodsService;
    @Autowired
    private CommentService commentService;
    @Autowired
    private activityService activityService;
    //根据前台传的id查询信息
    @RequestMapping(value ="/find",method = RequestMethod.GET)
    public String find(Model model, @RequestParam("id") Integer id, HttpServletRequest request){
        //根据id获得该商品的信息
        HttpSession session = request.getSession();
        session.setAttribute("goodsid",id);
        Goods goods =goodsService.findgoods(id);
        model.addAttribute("good",goods);
        Activity activities =activityService.findactivitys(goods.getActivityid());
        model.addAttribute("showactivity",activities);
        Integer price=goods.getPrice();
        model.addAttribute("price",price);


        //评论
        List<Comment> comments =  commentService.findAll();
        model.addAttribute("comment",comments);
        return "show";
    }
}
